package cloud.mbase.controller;

import cloud.mbase.entity.Result;
import cloud.mbase.util.ResourceNotFoundException;
import cloud.mbase.util.ResultUtil;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

@RestControllerAdvice
public class GlobleExceptionHandlerAdvice {
    @ExceptionHandler(value = ResourceNotFoundException.class)
    public Result resourceNotFoundException(HttpServletRequest request, Exception e) {
        return ResultUtil
                .getDefaultResult()
                .setStatus(HttpStatus.NOT_FOUND.value())
                .setUrl(request.getRequestURL().toString())
                .setMessage(e.getMessage());
    }
}
